<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        li {
            list-style: none;
        }

        ul {
            width: 900px;
            height: 40px;
            display: flex;
            border-bottom: 5px solid pink;
            margin: 30px auto;
            position: relative;
        }

        ul>li {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }

        ul>span {
            width: 100px;
            height: 5px;
            position: absolute;
            left: 0;
            bottom: -5px;
            background-color: red;
        }

        ul>p {
            position: absolute;
            width: 100px;
            height: 40px;
            background-color: skyblue;
            color: #fff;
            top: 0;
            left: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <ul>
        <li>第1个选项</li>
        <li>第2个选项</li>
        <li>第3个选项</li>
        <li>第4个选项</li>
        <li>第5个选项</li>
        <li>第6个选项</li>
        <li>第7个选项</li>
        <li>第8个选项</li>
        <li>第9个选项</li>
        <p>第1个选项</p>
        <span></span>
    </ul>

    <script src="../jquery/jquery-3.6.0.js"></script>

    <script>
        $("ul>li").mouseenter(function () {

            // 记录当前li的序号和文本
            const index = $(this).index()
            const text = $(this).text()

            // 给游标显示文本
            $("ul>p").text(text)

            // 游标的左偏移打到index*100
            $("ul>p,ul>span").css("left", index * 100)
        })
    </script>
</body>

</html>